﻿using SAO.OracleHelper.AttributeExtensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SAO.OracleHelper.ReflectionExtensions
{
    public static class RefExtensions
    {
        public static string SaoPage(this string str, int skip = 0, int take = 10)
        {
            if (string.IsNullOrEmpty(str))
                throw new Exception("SQL语句不能为空");
            return string.Format("select * from (select ROWNUM rn,temp.* from ({0}) temp) where rn >= {1} and rn <= {2}", str, (skip * take), (skip + 1) * take);
        }
        public static void SetValue(this PropertyInfo prop, object obj, object value)
        {
            prop.SetValue(obj, value, null);
        }
        public static object GetValue(this PropertyInfo prop, object obj)
        {
            return prop.GetValue(obj, null);
        }
        public static IEnumerable<T> GetCustomAttributes<[Nullable(0)] T>(this MemberInfo element) where T : Attribute
        {
            return (IEnumerable<T>)element.GetCustomAttributes(typeof(T));
        }
        public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, Type attributeType)
        {
            return Attribute.GetCustomAttributes(element, attributeType);
        }
        public static T GetCustomAttribute<[Nullable(0)] T>(this MemberInfo element) where T : Attribute
        {
            return (T)element.GetCustomAttribute(typeof(T));
        }
        public static Attribute GetCustomAttribute(this MemberInfo element, Type attributeType)
        {
            return Attribute.GetCustomAttribute(element, attributeType);
        }
    }
}
